class ClassListModel {
  int code;
  String msg;
  List<ClassListInfoModel> data;

  ClassListModel({
    required this.code,
    required this.msg,
    required this.data,
  });

  // 从 JSON 解析
  factory ClassListModel.fromJson(Map<String, dynamic> json) {
    return ClassListModel(
      code: json['code'] is int ? json['code'] as int : 0, // 确保 code 是 int
      msg: json['msg'] as String? ?? '', // 处理可能为 null 的情况
      data: (json['data'] as List?)?.map((e) => ClassListInfoModel.fromJson(e as Map<String, dynamic>)).toList() ?? [],
    );
  }
}

class ClassListInfoModel {
  String name;
  String blurb;
  String imgUrl;
  int categoryId;
  List<ClassChildrenModel> childrenList;

  ClassListInfoModel({
    required this.name,
    required this.blurb,
    required this.imgUrl,
    required this.categoryId,
    required this.childrenList,
  });

  // 从 JSON 解析
  factory ClassListInfoModel.fromJson(Map<String, dynamic> json) {
    return ClassListInfoModel(
      name: json['name'] as String? ?? '',
      blurb: json['blurb'] as String? ?? '',
      imgUrl: json['imgUrl'] as String? ?? '',
      categoryId: json['categoryId'] is int ? json['categoryId'] as int : 0,
      childrenList: (json['childrenList'] as List?)?.map((e) => ClassChildrenModel.fromJson(e as Map<String, dynamic>)).toList() ?? [],
    );
  }
}

class ClassChildrenModel {
  String name;
  String blurb;
  String imgUrl;
  int categoryId;
  int parentId;

  ClassChildrenModel({
    required this.name,
    required this.blurb,
    required this.imgUrl,
    required this.categoryId,
    required this.parentId,
  });

  // 从 JSON 解析
  factory ClassChildrenModel.fromJson(Map<String, dynamic> json) {
    return ClassChildrenModel(
      name: json['name'] as String? ?? '',
      blurb: json['blurb'] as String? ?? '',
      imgUrl: json['imgUrl'] as String? ?? '',
      categoryId: json['categoryId'] is int ? json['categoryId'] as int : 0,
      parentId: json['parentId'] is int ? json['parentId'] as int : 0,
    );
  }
}
